/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package models;

/**
 *
 * @author Thijs
 */
import java.util.ArrayList;
import java.util.List;

public class UserValidator
{

    public List<String> validate(UserForm userform)
    {
        List<String> errors = new ArrayList<String>();
        String name = userform.getName();
        if (name == null || name.trim().isEmpty())
        {
            errors.add("User must have a name");
        } else
        {

            UserStringValidator myUserStringValidator = new UserStringValidator();
            if (!myUserStringValidator.validate(name))
            {
                errors.add("Use regular expression for Productname");
            };

        }
        
        String plaats = userform.getCity();
        if (plaats == null || plaats.trim().isEmpty())
        {
            errors.add("User must have a city");
        } else
        {

            UserStringValidator myUserStringValidator = new UserStringValidator();
            if (!myUserStringValidator.validate(plaats))
            {
                errors.add("Use regular expression for Productname");
            };

        }
        
        String adres = userform.getStreetAddress();
        if (adres == null || adres.trim().isEmpty())
        {
            errors.add("User must have an address");
        } else
        {

            UserStringValidator myUserStringValidator = new UserStringValidator();
            if (!myUserStringValidator.validate(adres))
            {
                errors.add("Use regular expression for Productname");
            };

        }
        
        String price = userform.getHuisnummer();
        if (price == null || price.trim().isEmpty())
        {
            errors.add("User must have a house number");
        } else
        {
            try
            {
                Float.parseFloat(price);
            } catch (NumberFormatException e)
            {
                errors.add("no valid house number");
            }
        }
        return errors;
    }
}
